package com.lhd.controller;


import com.lhd.pojo.Good;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.pojo.Result;
import com.lhd.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/good")
public class GoodController {
    @Autowired
    GoodService goodService;

    @GetMapping("/all")
    public Result getAll(){
       List<Good> goods =  goodService.getAll();
       return Result.success(goods);
    }

    @GetMapping
    public Result getById(Integer id){
        goodService.getById(id);
        return Result.success();
    }
    @GetMapping("/condition")
    public Result getWithCondition(Good good, PageCondition pageCondition){
        PageBean<Good> pageBean = goodService.getWithCondition(good,pageCondition);
        return Result.success(pageBean);
    }
    @PutMapping
    public Result update(@RequestBody Good good){
        goodService.update(good);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Good good){
        goodService.add(good);
        return Result.success();
    }
    @DeleteMapping
    public Result remove(Integer id){
        goodService.remove(id);
        return Result.success();
    }
}
